package com.oocl.admin_platform.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.oocl.admin_platform.dao.ManagerDao;
import com.oocl.admin_platform.db.factory.DBConnectionFactory;
import com.oocl.admin_platform.pojo.Manager;
import com.oocl.admin_platform.pojo.Merchant;
import com.oocl.admin_platform.util.DBUtil;

public class ManagerDaoImpl implements ManagerDao {
	
	private static Logger logger = Logger.getLogger(ManagerDaoImpl.class);
	
	
	@Override
	public Manager findByuname(String uname) {
		// TODO Auto-generated method stub
		String sql = "select * from manager where uname=?";
		logger.info("enter findByuname method uname:   "+uname);
		Connection connection = null;
		PreparedStatement preparedStatement = null;
		ResultSet resultSet = null;
		Manager manager=null;
		connection=DBConnectionFactory.getInstance();
		try {
			preparedStatement = connection.prepareStatement(sql);
			preparedStatement.setString(1, uname);
			resultSet = preparedStatement.executeQuery();
			while (resultSet.next()) {
				manager=new Manager();
				manager.setId(resultSet.getString("id"));
				manager.setUname(resultSet.getString("uname"));
				manager.setPassword(resultSet.getString("password"));
			}
		} catch (SQLException e) {
			logger.error("fail on findByuname  uname "+uname+"  "+e.getMessage());
		} finally {
			DBUtil.close(connection, preparedStatement, resultSet);
		}
		return manager;
	}

}
